package com.tuanzi.loan.web.bean.product.model;

import com.tuanzi.loan.business.service.family.ActivityModelService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.family.ActivityModelSearchRequest;
import com.tuanzi.loan.vo.response.family.ActivityModelSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.product.model.LoanActivityModelLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;

/**
 * @Auther: hequnayu
 * @Date: 2019/7/8 15:05
 * @Description: 活动模板列表页
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class LoanActivityModelListBean extends JSFListingSessionBean<ActivityModelSearchRequest, ActivityModelSearchResponse> {

    @Autowired
    private ActivityModelService modelService;

    public void onReset() {
        initLazyDataModel();
    }

    public String onAdd() {
        return redirect("/views/product/model/info.xhtml");
    }

    public String onEdit(String id) {
        return redirect("/views/product/model/info.xhtml?id=" + id);
    }

    public void onDelete(Long id){
        modelService.deleteModel(id);
    }

    @Override
    protected String page() {
        return "/views/product/model/list.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new ActivityModelSearchRequest();
        lazyDataModel = new LoanActivityModelLazyDataModel($, session, modelService);
    }
}
